home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / CModalDialog C++ Class / CModalDialogClass.v100.sit / CModalDialog Class / CModalDialog.h < prev    next >
Text File  |  1995-10-11  |  5KB  |  132 lines

  1. // CModalDialog.h
  2. //     Copyright ⌐ 1995 by Michael F. Kamprath, All rights reserved.
  3. //
  4. // Contact information:
  5. //     mailto:kamprat@leonardo.net
  6. //     http://www.leonardo.net/kamprath
  7. //
  8. // License:
  9. //     This code may be freely used in free and shareware products. Commercial product
  10. //     users must supply me with a free, fully licensed copy of the product this code is
  11. //     used in. In either case, users should notify me of their use of this code.
  12. //
  13. //     This code may be freely distributed in it's non-modified form. It's original archive
  14. //     should be kept intact.
  15. //
  16. // Version History:
  17. //     v1.0.0 - Inititial release.
  18. //
  19.  
  20. #pragma once
  21. #ifndef __DIALOGS__
  22.     #include <Dialogs.h>
  23. #endif
  24.  
  25. class    CModalDialog
  26. {
  27. protected:
  28.     // theDialog is made protected so that inheiritted classes can
  29.     // have access to it. Not intended for public use.
  30.     DialogPtr            theDialog;
  31.  
  32. private:
  33.     // This is private stuff. No peeking!
  34.     friend pascal Boolean        CModalDialogFilter( DialogPtr theDlg, EventRecord *theEvent, short *itemHit);
  35.     
  36.     ModalFilterUPP        dialogFilterUPP;
  37.     short                dlogResID;
  38.  
  39.     short                defaultItem;
  40.     short                cancelItem;
  41.     
  42.     Boolean                showHasBeenCalled;
  43.     
  44.     // *private functions*
  45.     // DO NOT depend on these!
  46.  
  47.     void                GetDefaultRect( Rect& theRect );
  48.     void                FrameDefaultButton();
  49.     void                InvalidateDefaultRect(void);
  50.     
  51.     void                FakeDefaultButtonPress( );
  52.     void                FakeCancelButtonPress( );
  53.     
  54. public:
  55.  
  56.     // The Constructor and Destructor. You must pass the DLOG resource id
  57.     // for the dialog in the constructor. You may optionally specify non-default 
  58.     // values for the default and cancel button item IDs.
  59.     
  60.                         CModalDialog(    short    dlogResID,        // DLOG resource id
  61.                                         short    defaultID = 1,    // Default button
  62.                                         short    cancelID = 2);    // cancel button
  63.     virtual                ~CModalDialog();
  64.     
  65.     // Set's the Dialog port as the current GrafPort.
  66.     
  67.     void                SetDialogPort( void );
  68.     
  69.     // You may use these functions rather then their MacOS equivalents. 
  70.     
  71.     void                GetItemInfo( short item, short* itemType, Handle* itemHandle, Rect* itemRect );
  72.     void                SetItemInfo( short item, short itemType, Handle itemHandle, Rect* itemRect );
  73.     
  74.     // Change the Default and Cancel item. CModalDialog tracks the id's of the 
  75.     // default and cancel buttons to properly respond to their key equivalents
  76.     // and to prioperly draw a box around the default item. Changing the default item 
  77.     // automatically creates an update event to ensure the dialog is properly redrawn.
  78.     
  79.     void                SetDefaultItem( short newVal );
  80.     void                SetCancelItem( short newVal );
  81.     
  82.     // Show and hide the dialog. Note: Hiding a dialog is not the same as disposing it.
  83.     // Delete your CModalDialog object to release all memory ascociated with it.
  84.     
  85.     void                Show( void );
  86.     void                Hide( void );
  87.     
  88.     // Use DoOneModalLoop as you would the ::ModalDialog() routine in C code. It returns
  89.     // a short indicating the item number which was hit in the dialog.
  90.     
  91.     short                DoOneModalLoop( void );
  92.     
  93.     //
  94.     // Functions that you may overide.
  95.     //
  96.     
  97.     // If you want to customize the dialog's updates, override DrawDialog(). If you want 
  98.     // to have access to update events to update other application windows, override 
  99.     // UpdateFilter(). NOTE: DrawDialog() should only have drawing code. BeginUpdate() and
  100.     // EndUpdate() is called by UpdateFilter(). The CModalDialog version of DrawDialog just
  101.     // draws the DITL and frames the default button. If you override DrawDialog(), you should 
  102.     // head or tail patch it.
  103.     virtual void        DrawDialog( void );
  104.     
  105.     // These are the filter functions called by the ModalDialog filter for each dialog.
  106.     // The filter functions should be "conditionally head patched." That is, override the 
  107.     // function, but if your overide does nothing with the event that called it, call the
  108.     // CModalDialog version of the filter and return it's results. For example, if you want
  109.     // you dialog to respond to the user pressing the space bar, overide KeyDownFilter. In
  110.     // version, inspect the keydown event. If it is a space key, do your stuff and return true.
  111.     // If it isn't a space key, pass the event along to CModalDialog::KeyDownFilter() and return
  112.     // what CModalDialog::KeyDownFilter() returns.
  113.     
  114.     // Overide UpdateFilter() to have access to update events. The CModalDialog version
  115.     // calls DrawDialog() if the update event is for the this object's dialog.
  116.     virtual Boolean        UpdateFilter( DialogPtr theDlg, EventRecord *theEvent, short *itemHit);
  117.  
  118.     // Override KeyDownFilter() to have access to key down and autokey events. the CModalDialog
  119.     // looks for equivalent key presses for the default and cancel buttons.
  120.     virtual Boolean        KeyDownFilter( DialogPtr theDlg, EventRecord *theEvent, short *itemHit);
  121.     
  122.     // Override MouseDownFilter() to have access to mousedown events. The CModalDialog version
  123.     // does nothing with mouse down events. You should still head patch it though for future
  124.     // code compatibility (that is, in case I add menu handling routines for the Edit menu).
  125.     virtual Boolean        MouseDownFilter( DialogPtr theDlg, EventRecord *theEvent, short *itemHit);
  126.  
  127.     // Override OtherFilter() to have access to all other events. The CModalDialog version
  128.     // does nothing with any other event. You should still head patch it though for future
  129.     // code compatibility.
  130.     virtual Boolean        OtherFilter( DialogPtr theDlg, EventRecord *theEvent, short *itemHit);
  131. };
  132.